{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "from xunmi import *"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "indexer = Indexer(\"./fixtures/config.yml\")\n",
    "updater = indexer.get_updater()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "f = open(\"./fixtures/wiki_00.xml\")\n",
    "data = f.read()\n",
    "f.close()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "input_config = InputConfig(\"xml\", [(\"$value\", \"content\")], [(\"id\", (\"string\", \"number\"))])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "updater.update(data, input_config) "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "updater.commit()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [],
   "source": [
    "result = indexer.search(\"历史\", [\"title\", \"content\"], 5, 0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[(13.932347297668457,\n",
       "  '{\"id\":[22],\"title\":[\"历史\"],\"url\":[\"https://zh.wikipedia.org/wiki?curid=22\"]}'),\n",
       " (11.62932014465332,\n",
       "  '{\"id\":[399],\"title\":[\"非洲历史\"],\"url\":[\"https://zh.wikipedia.org/wiki?curid=399\"]}'),\n",
       " (11.526201248168945,\n",
       "  '{\"id\":[2239],\"title\":[\"美国历史\"],\"url\":[\"https://zh.wikipedia.org/wiki?curid=2239\"]}'),\n",
       " (11.521516799926758,\n",
       "  '{\"id\":[374],\"title\":[\"亚洲历史\"],\"url\":[\"https://zh.wikipedia.org/wiki?curid=374\"]}'),\n",
       " (11.342496871948242,\n",
       "  '{\"id\":[182],\"title\":[\"中国历史\"],\"url\":[\"https://zh.wikipedia.org/wiki?curid=182\"]}')]"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "result"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
